package com.tqz.rc.common.result;

/**
 * <p>公共返回类。
 *
 * @author tianqingzhao
 * @since 2021/8/30 14:53
 */
public class Result<T> {

    /**
     * 状态码，默认值200.
     */
    private Integer code = 200;

    /**
     * 消息体。
     */
    private String msg = "OK";

    /**
     * 数据。
     */
    private T data;

    public Result() {
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(T data) {
        this.data = data;
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public T getData() {
        return data;
    }

    public void setData(T data) {
        this.data = data;
    }

    public static Result ok() {
        return new Result();
    }

    public static Result ok(String msg) {
        Result result = new Result();
        result.msg = msg;
        return result;
    }

    public static Result error(Integer code, String msg) {
        Result result = new Result();
        result.code = code;
        result.msg = msg;
        return result;
    }
}
